<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <input type="text" v-model="username">
        <input type="text" v-model="password">
    </div>

    <script src="./lib/vue-2.6.12.js"></script>
    <script src="./lib/axios.js"></script>
    <script src="./lib/jquery-v3.6.0.js"></script>
    <script>
        const mv = new Vue({
            el: '#app',
            data: {
                username: 'hello vue.js',
                password: 'hello vue',
            },
            watch: {
                username: {
                    // handler 是固定写法，表示当 username 的值变化时，自动调用 handler 处理函数
                    handler: async function(newVal) {
                        if (newVal === '') return
                        const {
                            data: res
                        } = await axios.get('https://www.escook.cn/api/finduser/' + newVal)
                        console.log(res)
                    },
                    // 表示页面初次渲染好之后，就立即触发当前的 watch 侦听器
                    immediate: true
                }
            }

        })
    </script>
</body>

</html>